home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / pwd / c / getpw < prev    next >
Text File  |  1996-11-09  |  1KB  |  46 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/pwd/c/RCS/getpw,v $
  4.  * $Date: 1996/10/30 22:02:46 $
  5.  * $Revision: 1.1 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: getpw,v $
  10.  * Revision 1.1  1996/10/30 22:02:46  unixlib
  11.  * Initial revision
  12.  *
  13.  ***************************************************************************/
  14.  
  15. static const char rcs_id[] = "$Id: getpw,v 1.1 1996/10/30 22:02:46 unixlib Rel $";
  16.  
  17. #include <errno.h>
  18. #include <stdio.h>
  19. #include <pwd.h>
  20.  
  21.  
  22. /* Re-construct the password-file line for the given uid
  23.    in the given buffer.  This knows the format that the caller
  24.    will expect, but this need not be the format of the password file.  */
  25. int
  26. getpw (__uid_t uid, char *buf)
  27. {
  28.   register struct passwd *p;
  29.  
  30.   if (buf == NULL)
  31.     {
  32.       errno = EINVAL;
  33.       return -1;
  34.     }
  35.  
  36.   p = getpwuid (uid);
  37.   if (p == NULL)
  38.     return -1;
  39.  
  40.   if (sprintf (buf, "%s:%s:%u:%u:%s:%s:%s", p->pw_name, p->pw_passwd,
  41.            p->pw_uid, p->pw_gid, p->pw_gecos, p->pw_dir, p->pw_shell) < 0)
  42.     return -1;
  43.  
  44.   return 0;
  45. }
  46.